package com.example.nacostest.handler;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by smlz on 2019/11/22.   可以将token带到下个工程
 */
//@Configuration    // 加了这个就是全局配置
public class TulingRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        System.out.println("=================Feign Interceptor AccessToken: " + request.getHeader("token"));
        // 用postman去调用，带上头
        template.header("token", request.getHeader("token"));
    }
}
